package com.web.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.web.model.User;
import com.web.service.ServiceDAOFactory;
import com.web.service.UserService;

@WebServlet("/listUser.do")
public class UserServlet extends HttpServlet {

	public static final long serialVersionUID = 684872972934857L;
	
	@Override
	protected void doGet(HttpServletRequest req,HttpServletResponse resp) throws ServletException,IOException {
		doPost(req,resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req,HttpServletResponse resp) throws ServletException,IOException {
		UserService userService=ServiceDAOFactory.getUserService();
		try{
			List<User> userList =userService.findAll();
			req.setAttribute("userList", userList);
			req.getRequestDispatcher("/WEB-INF/view/users.jsp").forward(req, resp);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
}
